const {
  app_route_flag
} = require("./data/index.js")
App({
  onLaunch() {
    if (app_route_flag) {
      //初始化islogin
      wx.setStorageSync("isLogin", false)
      // 用于标记是否正在跳转到登录页
      let isRedirecting = false;
      // 监听所有路由跳转
      wx.onAppRoute((res) => {
        // 当前目标页面路径
        const currentPage = res.path;
        // 白名单，免登录
        const whiteList = [
          '/pages/user/wxlogin/wxlogin',
          '/pages/user/login/login',
          '/pages/user/login/contract/contract',
          '/pages/user/register/register'
        ];
        // 用户登录状态
        const isLogin = wx.getStorageSync('isLogin');
        // 未登录且不在白名单，跳转登录页
        if (!isLogin && !whiteList.includes(currentPage) && !isRedirecting) {
          isRedirecting = true;
          wx.redirectTo({
            url: '/pages/user/login/login',
            complete: () => {
              // 跳转完成后重置标志
              isRedirecting = false;
            }
          });
          //console.log(isLogin)
        }
      });
    }
  },
})